#ifndef _LOADACEEPTORMOUDLE_H
#define _LOADACEEPTORMOUDLE_H
#include "IObject.h"
#include <ace/OS.h>
#include <ace/Singleton.h>

class CLoadAcceptorMoudle
{
public:
	CLoadAcceptorMoudle()
	{
#ifdef _DEBUG
		hModule = ACE_OS::dlopen("AcceptorMoudleD.dll", RTLD_NOW);
#else
		hModule = ACE_OS::dlopen("AcceptorMoudle.dll", RTLD_NOW);
#endif // _DEBUG
		if (hModule == NULL)
		{
			return;
		}
		m_pFunConfig = (Fun_InitMainConfig)ACE_OS::dlsym(hModule, "InitConfig");
		m_pFunInit = (Fun_Init)ACE_OS::dlsym(hModule, "Init");
		m_pFunStart = (Fun_LibFun)ACE_OS::dlsym(hModule, "Start");
		m_pFunGetServerObject = (Fun_GetServerObject)ACE_OS::dlsym(hModule, "GetServerObject");
		m_pFunClose = (Fun_LibFun)ACE_OS::dlsym(hModule, "Close");
	}
	~CLoadAcceptorMoudle()
	{
		if (hModule != NULL)
		{
			ACE_OS::dlclose(hModule);
		}
		hModule = NULL;
	}

public:
	bool InitConfig(char* szConfigName)
	{
		if (m_pFunConfig == NULL)
		{
			return false;
		}
		return m_pFunConfig(szConfigName);
	}

	bool Init(IExDataManager* pExDataManager)
	{
		if (m_pFunInit == NULL)
		{
			return false;
		}
		return m_pFunInit(pExDataManager);
	}

	bool Start()
	{
		if (m_pFunStart == NULL)
		{
			return false;
		}
		return m_pFunStart();
	}

	bool Close()
	{
		if (m_pFunClose == NULL)
		{
			return false;
		}
		return m_pFunClose();
	}

	CServerObject* GetServerObject()
	{
		if (m_pFunGetServerObject == NULL)
		{
			return NULL;
		}
		return m_pFunGetServerObject();
	}

protected:
	typedef bool (*Fun_LibFun)();
	typedef bool (*Fun_Init)(IExDataManager*);
	typedef bool (*Fun_InitMainConfig)(char * szName);
	typedef CServerObject* (*Fun_GetServerObject)();

	Fun_InitMainConfig m_pFunConfig;
	Fun_Init m_pFunInit;
	Fun_LibFun m_pFunStart;
	Fun_LibFun m_pFunClose;
	Fun_GetServerObject m_pFunGetServerObject;
	ACE_SHLIB_HANDLE hModule;
};

typedef ACE_Singleton<CLoadAcceptorMoudle, ACE_Null_Mutex> App_LoadAcceptorMoudle;
#endif